package cn.java75.sp.service;

import cn.java75.sp.dao.AdminDao;
import cn.java75.sp.entity.*;
import cn.java75.sp.web.LoginBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
public class AdminService {
    @Autowired
   private AdminDao dao;
    @Resource
    private AuthenticationManager authenticationManager;

    public LoginUser login(String u, String p) {
        Authentication authentication = null;

            // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
            authentication = authenticationManager
                    .authenticate(new UsernamePasswordAuthenticationToken(u, p));
            LoginUser loginUser = (LoginUser) authentication.getPrincipal();

            return loginUser;

    }

}
